<template>
  <a-spin :spinning="confirmLoading" style="background: #fff">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="8" :hidden="true">
            <a-form-model-item label="流程名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bpmBizTitle" >
              <a-input :max-length="255" :disabled="formDisabled" v-model="model.bpmBizTitle" placeholder="请输入流程名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="单据编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bidNo">
              <a-input v-model="model.tenderCode" placeholder="请输入单据编号" disabled></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createTime">
              <j-date
                v-model="model.createTime"
                :show-time="true"
                date-format="YYYY-MM-DD HH:mm:ss"
                style="width: 100%"
                disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="申请人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proposer">
              <!-- <select-user-by-dep
                v-model="model.proposer"
                disabled/> -->
              <select-user-by-dep :multi="false" v-model="model.proposer" disabled />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="申请部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proposerDeptId">
              <j-select-depart v-model="model.proposerDeptId" disabled/>
            </a-form-model-item>
          </a-col>
          <a-divider>基本信息</a-divider>
          <a-row :gutter="40">
            <template v-if="model.applyType == '2'" >
              <a-col :span="8">
                <a-form-model-item label="关联投标档案" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderFinalId">
                  <select-omc-project-tender-input
                    :data-isolation="'tender_person'"
                    :data-type="'emp'"
                    :disabled="formDisabled"
                    v-model="model.tenderFinalId"
                    @back="popupCallback"/>
                </a-form-model-item>
              </a-col>
            </template>

            <a-col :span="8">
              <a-form-model-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="prepareProjectId">
                <template v-if="formDisabled">
                  <a-input :readOnly="true" v-model="model.projectName"  style="color: #1890FF;"   @click.prevent="getProjectDetail(model.prepareProjectId)"></a-input>
                </template>
                <template v-else>
                  <select-project-input
                    :use-type="'tender'"
                    :data-type="'username'"
                    :query-auth="true"
                    :is-bidding="'1'"
                    :disabled="formDisabled||model.applyType == '2'"
                    :tenderStatus="'0'"
                    v-model="model.prepareProjectId"
                    @back="handleProjectBack"/>
                  </template>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="项目承接人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="undertaker">
                <select-user-by-dep
                  :disabled="formDisabled"
                  :multi="false"
                  v-model="model.undertaker"
                  placeholder="请选择项目承接人"></select-user-by-dep>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="业绩归属年度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="year">
                <j-dict-select-tag
                  :disabled="formDisabled"
                  type="list"
                  v-model="model.year"
                  dictCode="yjgsnd"
                  placeholder="请选择业绩归属年度"/>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row :gutter="40">
            <a-col :span="8">
              <a-form-model-item
                label="项目地址"
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                prop="projectAddress"
              >
                <AddressChoice :disabled="formDisabled" v-model="model.projectAddress" ></AddressChoice>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item
                label="项目详细地址"
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                prop="detailedAddress"
              >
                <a-input :disabled="formDisabled" v-model="model.detailedAddress" placeholder="请输入项目详细地址"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="经营团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessTeam">
                <select-team-input
                   @back="changeVal"
                  :disabled="formDisabled"
                  v-model="model.businessTeam"
                  :tdlx="1"/>
              </a-form-model-item>
            </a-col>
            <!-- <a-col :span="8">
              <a-form-model-item label="经营公司" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessCompanyId">
                <select-Company-input :disabled="formDisabled" placeholder="请选择经营公司" v-model="model.businessCompanyId" disabled /> 
              </a-form-model-item>
            </a-col> -->
          </a-row>

          <a-row :gutter="40">
            <a-col :span="8">
              <a-form-model-item label="报名截止时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="entriesEndDate">
                <a-date-picker
                  show-time
                  :disabled="editFildDisabled"
                  placeholder="请选择报名截止时间"
                  v-model="entriesEndDate"
                  @change="(date, dateStr) => {
                    this.$set(this.model, 'entriesEndDate', dateStr);
                    this.$set(this.model, 'tenderEndDate', undefined)
                    this.tenderEndDate = undefined;
                  }"
                  :disabledDate="disabledEntriesEndDate"
                  format="YYYY-MM-DD HH:mm:ss"
                  style="width: 100%"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="投标截止时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderEndDate">
                <a-date-picker
                  show-time
                  :disabled="editFildDisabled"
                  placeholder="请选择投标截止时间"
                  v-model="tenderEndDate"
                  @change="(date, dateStr) => { this.$set(this.model, 'tenderEndDate', dateStr) }"
                  :disabledDate="disabledTenderEndDate"
                  format="YYYY-MM-DD HH:mm:ss"
                  style="width: 100%"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="业主单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ownerUnit">
                <select-customer-input
                  :disabled="formDisabled"
                  v-model="model.ownerUnit"
                  commercialType="1"
                  @change="ownerUnitChange"/>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row :gutter="40">
            <a-col :span="8">
              <a-form-model-item label="业主联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ownerLinkman">
                <j-dict-select-tag
                  :disabled="formDisabled"
                  type="list"
                  v-model="model.ownerLinkman"
                  :dictCode="customer_contacts"
                  placeholder="请选择联系人"
                  @input="contactsChange"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="业主联系方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ownerTel">
                <a-input :disabled="formDisabled" v-model="model.ownerTel" placeholder="请输入业主联系方式"></a-input>
              </a-form-model-item>
            </a-col>

            <a-col :span="8">
              <a-form-model-item label="招标方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="biddingMethod">
                <j-dict-select-tag
                  :disabled="formDisabled"
                  type="list"
                  v-model="model.biddingMethod"
                  dictCode="bidding_method"
                  placeholder="请选择招标方式"/>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row :gutter="40">
            <a-col :span="8">
              <a-form-model-item label="招标控制价（元）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="controlPrice">
                <a-input-number
                  :precision="2"
                  :disabled="editFildDisabled"
                  v-model="model.controlPrice"
                  placeholder="请输入招标控制价"
                  style="width: 100%"
                  :min="0"
                  :max="999999999"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="标书费（元）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="entryFee">
                <a-input-number
                  :precision="2"
                  :disabled="editFildDisabled"
                  v-model="model.entryFee"
                  placeholder="请输入标书费"
                  style="width: 100%"
                  :min="0"
                  :max="999999999"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="投标保证金（元）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderBond">
                <a-input-number
                  :precision="2"
                  :disabled="editFildDisabled"
                  v-model="model.tenderBond"
                  placeholder="请输入投标保证金"
                  style="width: 100%"
                  :min="0"
                  :max="999999999"/>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-col :span="24">
            <a-form-model-item label="项目公示信息" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectPublicity">
              <a-textarea :disabled="formDisabled" :max-length="500" v-model="model.projectPublicity" rows="4" placeholder="请输入项目公示信息"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="投标内容概要" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderContent">
              <a-textarea :maxLength="500" :disabled="formDisabled" v-model="model.tenderContent" rows="4" placeholder="请输入投标内容概要"/>
            </a-form-model-item>

            <a-form-model-item label="招标文件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderFile">
              <j-upload v-if="!formDisabled" :disabled="formDisabled" v-model="model.tenderFile"></j-upload>
              <a-button v-else icon="download" @click="viewFile(model.tenderFile)">文件列表</a-button>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="8">
            <a-form-model-item label="投标类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderType">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.tenderType"
                dictCode="tender_type"
                placeholder="请选择投标类别"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="基准分值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="baseScore">
              <a-input-number
                :disabled="formDisabled"
                v-model="model.baseScore"
                placeholder="请输入基准分值"
                :min="0"
                :max="99999"
                style="width: 100%;"/>
            </a-form-model-item>
          </a-col> -->

          <!--<a-col :span="8">
            <a-form-model-item label="投标部门负责人审核" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="baseScore">
              <select-user-by-dep
                :disabled="formDisabled"
                v-model="model.deptLeading"
                placeholder="请选择投标部门负责人审核"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="工程师审核" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="baseScore">
              <select-user-by-dep
                :disabled="formDisabled"
                v-model="model.engineer"
                placeholder="请选择工程师审核"/>
            </a-form-model-item>
          </a-col>-->
        </a-row>
                <a-divider>投标单位信息</a-divider>
                <a-row :gutter="48">
                  <a-col :span="8">
                    <a-form-model-item label="投标部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderDept">
                      <j-select-depart  :disabled="formDisabled" v-model="model.tenderDept"/>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="8">
                    <a-form-model-item label="投标编制人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderPerson">
                      <!--              <j-dict-select-tag :disabled=formDisabled type="list" v-model="model.tenderPerson" dictCode="" placeholder="请选择投标编制人" />-->
                      <select-user-by-dep disabled  :multi="false"
                                          v-model="model.tenderPerson" ></select-user-by-dep>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="8">
                    <a-form-model-item label="投标单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderUnit">
                      <!--              <j-dict-select-tag :disabled=formDisabled type="list" v-model="model.tenderUnit" dictCode="erp_company_files,file_name,id,del_flag = 0 and audit_status = 2" placeholder="请选择投标单位"/>-->
                      <select-Company-input :disabled="formDisabled" v-model="model.tenderUnit"  />
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="8">
                    <a-form-model-item label="是否需要协调" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="needHelp">
                      <j-dict-select-tag
                        @input="isTeamworkChange"
                        disabled
                        type="radio"
                        v-model="model.needHelp"
                        dictCode="YES_OR_NO"
                        placeholder="请选择是否需要协调"/>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="8">
                    <a-form-model-item
                      label="协同人员（多选）"
                      v-show="model.needHelp==1"
                      :labelCol="labelCol"
                      :wrapperCol="wrapperCol"
                      prop="helperIds">
                      <select-user-by-dep disabled  :multi="true"
                                          v-model="model.helperIds" ></select-user-by-dep>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="24">
                    <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remarks">
                      <a-textarea disabled :maxLength="500"  v-model="model.remarks" rows="4" placeholder="备注"/>
                    </a-form-model-item>
                  </a-col>
        <a-divider>业务分类</a-divider>
        <!--          业务分类-->
        <a-col :span="24">
          <div style="margin-bottom: 6px;margin-top: 6px">
            <a-button @click="handleAdd" v-if="!formDisabled" type="primary">新增</a-button>
          </div>
          <a-table
            ref="table"
            size="middle"
            rowKey="id"
            :loading="loading"
            :columns="columns"
            :pagination="false"
            :data-source="dataSource">
            <span slot="action" slot-scope="text, record">
              <template v-if="!formDisabled">
                <a @click="handleEdit(record)">编辑</a>
                <a-divider type="vertical"/>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </template>
            </span>
          </a-table>
        </a-col>
          <!-- <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
            <a-button @click="submitForm">提 交</a-button>
          </a-col> -->
        </a-row>
      </a-form-model>
      <common-flow-list v-if="formBpm && model.bpmStatus !== '1'" :formData="formData" style="margin-top: 10px"></common-flow-list>
      <view-file-modal ref="viewFileModal"></view-file-modal>
      <erp-omc-tender-service-modal ref="itemList" @ok="modalFormOk"></erp-omc-tender-service-modal>
      <!-- 项目详情开始 -->
      <erp-project-report-modal  ref="reportForm"></erp-project-report-modal>
    </j-form-container>
    <a-row :gutter="48">
      <a-col :span="24" style="text-align: center;margin-top: 15px">
        <a-button type="primary" v-if="formBpm" :style="{ marginRight: showFlowSubmitButton?'10px':'0px' }" @click="onPrint">打印</a-button>
        <a-button @click="submitForm('submit')" v-if="showFlowSubmitButton">提 交</a-button>
      </a-col>
    </a-row>

    <ErpOmcTenderFormPrint id="tenderContent" v-if="formBpm" class="print_style" :formData="model" :formDataHistory="formData"></ErpOmcTenderFormPrint>
  </a-spin>
</template>

<script>

import { getAction, httpAction } from '@/api/manage'
import { viewFile } from '@/utils/util'
import moment from 'moment'
import { mapGetters } from 'vuex'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
import SelectCustomerInput from '@/views/scy/components/SelectCustomerInput'
import ViewFileModal from '@/views/scy/components/ViewFileModal'
import { filterMultiDictText, initDictOptions } from '@comp/dict/JDictSelectUtil';
import ErpOmcTenderServiceModal from '@/views/erp/omc/tender/modules/ErpOmcTenderServiceModal'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin';
import SelectProjectInput from '@/views/scy/components/SelectProjectInput';
import JSelectDepart from '../../../../../components/jeecgbiz/JSelectDepart';
import AddressChoice from '@/components/AddressChoice/AddressChoice';
import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput';
import SelectOmcProjectTenderInput from '@/views/scy/components/SelectOmcProjectTenderInput';
import CommonFlowList from '@/views/components/CommonFlowList.vue';
import ErpProjectReportModal from '@/views/erp/report/project/modules/ErpProjectReportModal'
import Print from '@/utils/print/printarea.js';
import ErpOmcTenderFormPrint from './ErpOmcTenderFormPrint' // 打印
export default {
  name: 'ErpOmcTenderForm',
  mixins: [DisabledAuthFilterMixin, viewFile],
  components: {
    ErpProjectReportModal,
    SelectCompanyInput,
    JSelectDepart,
    ViewFileModal,
    SelectTeamInput,
    SelectCustomerInput,
    ErpOmcTenderServiceModal,
    SelectProjectInput,
    AddressChoice,
    SelectUserByDep,
    SelectOmcProjectTenderInput,
    CommonFlowList,
    ErpOmcTenderFormPrint
  },
  props: {
    // 流程表单data
    formData: {
      type: Object,
      default: () => {
      },
      required: false
    },
    // 表单模式：true流程表单 false普通表单
    formBpm: {
      type: Boolean,
      default: false,
      required: false
    },
    // 表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  watch: {
    activeKey(key) {
      this.$forceUpdate()
    }
  },
  data() {
    return {
      activeKey: ['1', '2', '3', '4'],
      loading: false,
      fileLoading: false,
      resLoading: false,
      columns: [
        {
          title: '业务分类',
          align: 'center',
          dataIndex: 'serviceType'
        },
        {
          title: '业务名称',
          align: 'center',
          dataIndex: 'serviceName'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ],
      fileColumns: [
        {
          title: '投标文件编号',
          align: 'center',
          dataIndex: 'bidNo'
        },
        {
          title: '难度系数',
          align: 'center',
          dataIndex: 'difficultyCoefficient'
        },
        {
          title: '标书费（元）',
          align: 'center',
          dataIndex: 'bidFee'
        },
        {
          title: '投标单位',
          align: 'center',
          dataIndex: 'tenderUnitId_dictText'
        },
        {
          title: '投标部门',
          align: 'center',
          dataIndex: 'tenderDept_dictText'
        },
        {
          title: '投标金额（元）',
          align: 'center',
          dataIndex: 'tenderAmount'
        },
        {
          title: '开标方式',
          align: 'center',
          dataIndex: 'bidMethod_dictText'
        },
        {
          title: '文件类型',
          align: 'center',
          dataIndex: 'fileType_dictText'
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'bpmStatus_dictText'
        }
      ],
      resColumns: [
        {
          title: '投标结果编号',
          align: 'center',
          dataIndex: 'bidResultNo'
        },
        {
          title: '开标日期',
          align: 'center',
          dataIndex: 'bidOpeningData'
        },
        {
          title: '中标结果',
          align: 'center',
          dataIndex: 'bidResult_dictText'
        },
        {
          title: '中标金额',
          align: 'center',
          dataIndex: 'tenderAmount'
        },
        // {
        //   title: '投标部门',
        //   align: 'center',
        //   dataIndex: 'bidResult_dictText'
        // },
        {
          title: '中标单位',
          align: 'center',
          dataIndex: 'tenderUnit'
        },
        {
          title: '招标代理费（元）',
          align: 'center',
          dataIndex: 'agentFee'
        },
        {
          title: '履约保证金（元）',
          align: 'center',
          dataIndex: 'bail'
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'bpmStatus_dictText'
        }
      ],

      dataSource: [],
      fileDataSource: [],
      resDataSource: [],
      /* 分页参数 */
      fileIpagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30', '50', '100', '200'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      /* 分页参数 */
      resIpagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30', '50', '100', '200'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      isShowTeamwork: false,
      model: {
        handlerName: ''
      },
      labelCol: {},
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 24 }
      },
      dictOptions: {},
      confirmLoading: false,
      validatorRules: {
        tenderUnit: [
          { required: true, message: '请选择投标单位!' }
        ],
        tenderDept: [
          { required: true, message: '请选择投标部门!' }
        ],
        prepareProjectId: [
          { required: true, message: '请选择预立项项目!' }
        ],
        undertaker: [
          { required: true, message: '请选择承接人!' }
        ],
        year: [
          { required: true, message: '请选择业绩归属年度!' }
        ],
        projectAddress: [
          { required: true, message: '请选择项目地址!' }
        ],
        detailedAddress: [
          { required: true, message: '请输入项目详细地址!' }
        ],
        businessTeam: [
          { required: true, message: '请选择经营团队!' }
        ],
        // TASK#1949非必填
        // entriesEndDate: [
        //   { required: true, message: '请选择报名截止日期!' }
        // ],
        // tenderEndDate: [
        //   { required: true, message: '请选择投标截止日期!' }
        // ],
        ownerUnit: [
          { required: true, message: '请选择业主单位!', trigger: 'change' }
        ],
        ownerLinkman: [
          { required: true, message: '请选择业主联系人!' }
        ],
        ownerTel: [
          { required: true, message: '请输入业主联系方式!', trigger: 'change' },
          { pattern: /(^1\d{10}$|^(0\d{2,3}-?|\(0\d{2,3}\))?[1-9]\d{4,7}(-\d{1,8})?$)|(^\/$)/, message: '请输入正确的联系方式!' }
        ],
        // TASK#1949非必填
        biddingMethod: [
          { required: true, message: '请选择招标方式!' }
        ],
        controlPrice: [
          { required: false },
          { pattern: /^([0]|([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' }
        ],
        entryFee: [
          { required: false },
          { pattern: /^([0]|([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' }
        ],
        tenderBond: [
          { required: false },
          { pattern: /^([0]|([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' }
        ],
        baseScore: [
          { required: false },
          { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!' }
        ]
      },
      url: {
        queryProjectReportById: '/api/erp/project/report/erpProjectReport/queryById',
        add: '/api/erp/omc/tender/erpOmcTender/add',
        edit: '/api/erp/omc/tender/erpOmcTender/edit',
        queryById: '/api/erp/omc/tender/erpOmcTender/queryById',
        queryPrepareProjectById: '/api/erp/omc/prepareproject/erpOmcPrepareProject/queryById',
        queryTenderServiceListByTenderId: '/api/erp/omc/tender/erpOmcTenderService/queryTenderServiceListByTenderId',
        queryOmcTenderFileList: '/api/erp/omc/tenderfile/erpOmcTenderFile/list',
        queryOmcTenderResultList: '/api/erp/omc/tenderresult/erpOmcTenderResult/list'
      },
      customer_contacts: undefined,
      sutdata: '',
      entriesEndDate: undefined,
      tenderEndDate: undefined
    }
  },
  computed: {
    formDisabled() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return false
        }
        return true
      }
      return this.disabled
    },
    // 投标审核需要动态禁用的状态字段
    editFildDisabled() {
      // 新增和变更的时候只能看不能填
      return true
    },
    proDisabled() {
        return true
    },
    showFlowSubmitButton() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return true
        }
      }
      return false
    }
  },
  created() {
    // 备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
    // 如果是流程中表单，则需要加载流程表单data
    this.showFlowData();
    this.initDictConfig();
    if (this.formDisabled) {
      this.columns.pop()
    }
  },
  mounted() {
  },
  methods: {
    onDetail(id) {
      const that = this
      this.$nextTick(() => {
        getAction(this.url.queryProjectReportById, { id }).then((res) => {
          if (res.success) {
            const model = res.result
            that.$refs.reportForm.getDetail(model);
            that.$refs.reportForm.title = '项目一览表';
          }
        })
      })
    },
    changeVal(val){
      this.$set(this.model, 'businessCompanyId',val[0].belongCompanyId)
    },
    initDictConfig() {
      // initDictOptions('erp_company_files,file_name,id, del_flag=0 and audit_status = 2').then((res) => {
      //   if (res.success) {
      //     this.$set(this.dictOptions, 'tenderUnit', res.result)
      //   }
      // })
      initDictOptions('erp_company_files,file_name,id ').then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'tenderUnit', res.result)
        }
      })
      initDictOptions('sys_depart,depart_name,id').then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'tenderDept', res.result)
        }
      })
      initDictOptions('erp_employee_file,name,id').then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'tenderPerson', res.result)
        }
      })
      initDictOptions('YES_OR_NO').then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'needHelp', res.result)
        }
      })
    },
    // 改变当前是新增页面还是变更页面的状态
    changeStatus(typeStatus) {
      this.typeStatus = typeStatus;
    },

    handleAdd() {
      this.$refs.itemList.add();
      this.$refs.itemList.title = '新增';
      this.$refs.itemList.disableSubmit = false;
    },
    handleEdit(record) {
      this.$refs.itemList.edit(record);
      this.$refs.itemList.title = '修改';
      this.$refs.itemList.disableSubmit = false;
    },
    handleDelete(id) {
      for (let i = 0; i < this.dataSource.length; i++) {
        if (this.dataSource[i].id == id) {
          this.dataSource.splice(i, 1);
        }
      }
    },
    modalFormOk(data) {
      debugger;
      this.loading = true;
      let flag = true;
      // debugger;
      for (let i = 0; i < this.dataSource.length; i++) {
        if (this.dataSource[i].id == data.id) {
          this.dataSource.splice(i, 1, data);
          flag = false;
        }
      }
      if (flag) {
        this.dataSource.push(data);
      }
      this.loading = false;
    },
    // 是否协同
    isTeamworkChange(e) {
      if (e == '1') {
        this.isShowTeamwork = true
      } else {
        // 选择否了就清空
        this.$set(this.model, 'helperIds', null)
        this.isShowTeamwork = false
      }
    },
    // 业主单位
    ownerUnitChange() {
      this.customer_contacts = 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + this.model.ownerUnit + '\'';
      this.$set(this.model, 'ownerLinkman', undefined)
      this.$set(this.model, 'ownerTel', undefined)
    },
    // 业主联系人
    contactsChange(val) {
      this.$set(this.model, 'ownerLinkman', val)
      getAction('/api/erp/omc/customermanager/erpOmcCustomerManagerContact/queryById', { id: val }).then((res) => {
        if (res.success) {
          let data = res.result.records || res.result
          this.$set(this.model, 'ownerTel', data.lxfs)
        }
      })
    },
    // 选择预立项
    choosePrepareProjectChange(e) {
      if (e) {
        let params = { id: e };
        getAction(this.url.queryPrepareProjectById, params).then((res) => {
          if (res.success) {
            if (res.result) {
              this.model.projectName = res.result.mc
              this.model.projectType = res.result.xmlx
              this.model.undertaker = res.result.cjr
              this.model.year = res.result.yjgsnd
              this.model.businessTeam = res.result.ywtd
              this.model.ownerUnit = res.result.yzdw
              this.model.ownerLinkman = res.result.lxr
              this.model.ownerTel = res.result.lxdh
              this.model.projectAddress = res.result.ssq
              this.dataSource = res.result.serviceList;
              this.model = Object.assign({}, this.model);
            }
          }
        });
      }
    },
    ...mapGetters(['userInfo']),
    add(value) {
      this.userName = this.userInfo().empName;// 当前登录人名称
      this.dataSource = []
      this.edit(this.modelDefault);
      this.model.tenderCode = value && value.tenderCode ? value.tenderCode : '';
      //   迭代11 修改标题
      // this.model.bpmBizTitle = this.userName + '-' + this.model.tenderCode//标题
      this.model.proposer = value && value.loginUser && value.loginUser.empId ? value.loginUser.empId : '';
      this.model.proposerDeptId = this.userInfo().deptId;
      this.model.isTeamwork = 0;
      this.model.createTime = moment().format('YYYY-MM-DD HH:mm:ss');
      this.entriesEndDate = undefined;
      this.tenderEndDate = undefined;
      // 变更隐藏字段 applyType
      this.model.applyType = value && value.applyType ? value.applyType : ''
    },
    edit(record) {
      this.$refs.form.resetFields();
      this.model = Object.assign({}, record);
      this.isShowTeamwork = this.model.isTeamwork === '1'
      this.entriesEndDate = this.model.entriesEndDate;
      this.tenderEndDate = this.model.tenderEndDate;
      if (this.model.id) {
          this.customer_contacts = 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + this.model.ownerUnit + '\'';
        // eslint-disable-next-line no-unused-expressions
        getAction(this.url.queryTenderServiceListByTenderId, { id: this.model.id }).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records || res.result
          }
        }),
        getAction(this.url.queryOmcTenderFileList, { tenderId: this.model.id }).then((res) => {
          if (res.success) {
            this.fileDataSource = res.result.records || res.result
            this.fileIpagination.total = res.result.total;
          }
        }),
        getAction(this.url.queryOmcTenderResultList, { tenderId: this.model.id }).then((res) => {
          if (res.success) {
            this.resDataSource = res.result.records || res.result
            this.resIpagination.total = res.result.total
          }
        })
      }
      this.visible = true;
    },
    // 渲染流程表单数据
    showFlowData() {
      if (this.formBpm === true) {
        let params = { id: this.formData.dataId };
        getAction(this.url.queryById, params).then((res) => {
          if (res.success) {
            this.edit(res.result);
          }
        });
      }
    },

    submitForm(type) {
      const that = this;
      if (type == 'draft') {
        // 代表保存草稿不做校验
        this.submit(type)
      } else if (type == 'submit') {
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.submit(type)
          } else {
            that.$emit('unButtonDisable')
          }
        })
      } else {
        console.log('传参数，保存：draft，提交：submit')
      }
    },
    submit (type) {
      const that = this;
      that.confirmLoading = true;
      let httpurl = '';
      let method = '';
      if (!this.model.id) {
        httpurl += this.url.add;
        method = 'post';
      } else {
        httpurl += this.url.edit;
        method = 'put';
      }
      this.model.itemList = this.dataSource || [];
      httpAction(httpurl, this.model, method).then((res) => {
        if (res.success) {
          that.$message.success('保存成功!');
          if (method == 'post') {
            that.model.id = res.result;
          }
          that.$emit('ok', type, that.model);
        } else {
          that.$message.warning(res.message);
          that.$emit('unButtonDisable');
        }
      }).catch((error) => {
        that.$emit('unButtonDisable', error);
      }).finally(() => {
        that.confirmLoading = false;
      })
    },
    popupCallback(tenderFinal) {
      // this.model = Object.assign(this.model, obj);
      this.$set(this.model, 'undertaker', tenderFinal.undertaker)
      this.$set(this.model, 'year', tenderFinal.year)
      // this.$set(this.model,'tenderFinalId',tenderFinal.id)
      this.$set(this.model, 'tenderFinalCode', tenderFinal.tenderCode)
      this.$set(this.model, 'projectName', tenderFinal.projectName)
      this.$set(this.model, 'prepareProjectId', tenderFinal.prepareProjectId)
      this.$set(this.model, 'projectAddress', tenderFinal.projectAddress)
      this.$set(this.model, 'detailedAddress', tenderFinal.detailedAddress)
      this.$set(this.model, 'businessTeam', tenderFinal.businessTeam)
      this.$set(this.model, 'businessCompanyId', tenderFinal.businessCompanyId)  // 经营公司
      this.$set(this.model, 'entriesEndDate', tenderFinal.entriesEndDate)
      this.entriesEndDate = tenderFinal.entriesEndDate
      this.$set(this.model, 'tenderEndDate', tenderFinal.tenderEndDate)
      this.tenderEndDate = tenderFinal.tenderEndDate
      this.$set(this.model, 'ownerUnit', tenderFinal.ownerUnit)
      this.$set(this.model, 'ownerLinkman', tenderFinal.ownerLinkman)
      this.$set(this.model, 'ownerTel', tenderFinal.ownerTel)
      this.$set(this.model, 'biddingMethod', tenderFinal.biddingMethod)
      this.$set(this.model, 'controlPrice', tenderFinal.controlPrice)
      this.$set(this.model, 'entryFee', tenderFinal.entryFee)
      this.$set(this.model, 'tenderBond', tenderFinal.tenderBond)
      this.$set(this.model, 'projectPublicity', tenderFinal.projectPublicity)
      this.$set(this.model, 'tenderContent', tenderFinal.tenderContent)
      this.$set(this.model, 'tenderFile', tenderFinal.tenderFile)
      // this.$set(this.model,'tenderType',obj.tender_type)
      // this.$set(this.model,'baseScore',obj.base_score)
      this.isShowTeamwork = tenderFinal.is_teamwork === '1'
      this.$set(this.model, 'isTeamwork', tenderFinal.isTeamwork)
      // 投标部门
      this.$set(this.model, 'tenderDept', tenderFinal.tenderDept)
      // 投标编制人
      this.$set(this.model, 'tenderPerson', tenderFinal.tenderPerson)
      // 投标单位
      this.$set(this.model, 'tenderUnit', tenderFinal.tenderUnit)
      // 是否需要协调
      this.$set(this.model, 'needHelp', tenderFinal.needHelp === null ? '' : tenderFinal.needHelp)
      // fix:BUG#4985 投标变更-备注字段信息未带出 start
      this.$set(this.model, 'remarks', tenderFinal.remarks)
      // fix:BUG#4985 投标变更-备注字段信息未带出 end
      // 协同人员（多选）
      this.$set(this.model, 'helperIds', tenderFinal.helperIds)

      this.$set(this.model, 'teamworkPerson', tenderFinal.teamworkPerson)
      this.customer_contacts = 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + this.model.ownerUnit + '\'';
      // 查询要业务信息档案
      getAction('/api/erp/omc/tender/erpOmcTenderServiceFinal/queryTenderServiceListByTenderId', { id: tenderFinal.id }).then(res => {
        if (res.success) {
          this.dataSource = res.result || []
        }
      })
      // 查询投标单位
      getAction('/api/erp/omc/tender/erpOmcTenderUnitFinal/queryTenderListByTenderId', { id: tenderFinal.id }).then(res => {
        if (res.success) {
          this.unitDataSource = res.result || []
        }
      })
    },
    getProjectDetail(val) {
      // 查询项目信息
      const that = this
      this.$nextTick(() => {
        getAction(this.url.queryProjectReportById, { id: val }).then(res => {
          if (res.success) {
              const model = res.result
              that.$refs.reportForm.getDetail(model);
              that.$refs.reportForm.title = '项目一览表';
          }
        })
      })
    },
    handleProjectBack(project) {
      this.$set(this.model, 'prepareProjectId', project[0].id)
      this.$set(this.model, 'projectName', project[0].projectName)
      this.$set(this.model, 'bpmBizTitle', project[0].projectName + '-' + this.userInfo().empName + '-' + this.model.tenderCode)// 标题
      this.$set(this.model, 'undertaker', project[0].undertaker)
      this.$set(this.model, 'year', project[0].year)
      this.$set(this.model, 'businessCompanyId', project[0].businessCompanyId)  // 经营公司
      this.$set(this.model, 'projectAddress', project[0].areaCode)
      this.$set(this.model, 'detailedAddress', project[0].projectAddress)
      this.$set(this.model, 'businessTeam', project[0].oldTeamId?project[0].oldTeamId:project[0].teamName)
      this.$set(this.model, 'ownerUnit', project[0].ownerUnit)
      this.$set(this.model, 'ownerLinkman', project[0].contacts)
      this.$set(this.model, 'ownerTel', project[0].contactTel)
      this.customer_contacts = 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + this.model.ownerUnit + '\'';
      getAction('/api/erp/omc/project/erpOmcProjectTask/listById', { id: project[0].id }).then(res => {
          if (res.length > 0) {
            this.dataSource = res || res.result || []
            this.dataSource.forEach(ele => {
              ele.serviceType = ele.categoryCode
              ele.serviceName = ele.categoryName
            });
          }
      })
    },
    disabledEntriesEndDate(currentDate) {
      return currentDate < moment(this.model.createTime).subtract('day')
    },
    disabledTenderEndDate(currentDate) {
      return currentDate < moment(this.model.entriesEndDate).subtract('day')
    },

    // 点击打印
    onPrint () {
        let print = new Print({
          el: '#tenderContent',
          popTitle: '投标详情 · 禾美环保',
          endCallback() {

          }
        })
      }
  }
}
</script>
<style scoped>
.ant-divider {
  font-size: 10px;
  font-weight: bold;
}

/*.ant-tabs{
  width: 850px;
}*/
.ant-row{
  margin: 0 !important;
}

.print_style{
  position: absolute;
  top: 0;
  z-index: -1111;
}
</style>
<style>
  @import "../../../../../utils/print.css";
</style>
